package models.bbs;


import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import org.bson.types.ObjectId;

import play.data.validation.Required;
import play.modules.morphia.Model;

import com.google.code.morphia.annotations.Entity;

@Entity
public class Article extends Model {
	
	@Required private String title;
	@Required private String content;
	@Required private String author;
	private int hitCount = 0;
	private Date createdDateTime;
	private List<Comment> comments = new ArrayList<Comment>();
	
	public Article(String title, String content, String author){
		this.title = title;
		this.content = content;
		this.author = author;
		this.createdDateTime = Calendar.getInstance().getTime();
	}
	
	public void hit(){
		this.hitCount++;
	}
	
	public String getTitle(){
		return this.title;
	}
	
	public String getContent(){
		return this.content;
	}
	
	public String getAuthor(){
		return this.author;
	}
	
	public int getHitCount(){
		return this.hitCount;
	}
	
	public boolean isNewArticle(){
		boolean result = false;
		Calendar twoDayAgo = Calendar.getInstance();
		twoDayAgo.add(Calendar.DAY_OF_MONTH, -2);

		if(twoDayAgo.getTime().compareTo(createdDateTime) < 0){
			result = true;
		}
		return result;
	}
	
	public Date getCreatedDateTime(){
		return this.createdDateTime;
	}
	
	public List<Comment> getComments(){
		return this.comments;
	}
	
	public void addComment(Comment comment){
		this.comments.add(comment);
	}
}
